<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="ThemeBucket">
  <link rel="shortcut icon" href="#" type="../image/png">
  <title>Demo</title>
  <!--data table-->
  <link rel="stylesheet" href="../js/data-tables/DT_bootstrap.css" />
  <link rel="stylesheet" href="../js/data-tables/DT_bootstrap.css" />
  <link rel="stylesheet" type="text/css" href="../js/bootstrap-timepicker/css/timepicker.css" />
  <link rel="stylesheet" type="text/css" href="../js/bootstrap-datetimepicker/css/datetimepicker-custom.css" />
  <link href="../css/style.css" rel="stylesheet">
  <link href="../css/style-responsive.css" rel="stylesheet">

</head>
<body class="sticky-header" onload="indexmenu('${oneMenu}','${twoMenu}');">
<%@ include file="../index/index.jsp" %>
<section>
	<div class="main-content">

        <!-- 地址栏-->
		<div class="page-heading">
            <h3>
                	后台管理系统
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">优惠卷管理</a>
                </li>
                <li class="active">优惠卷设置</li>
            </ul>
        </div>   
		<!--这里是写一些内容的  -->
		<div class="row">
	        <div class="col-sm-12">
	        	<section class="panel">
		        	<div class="panel-body">
		        		<div class="adv-table">
		      				<div id="dynamic-table_wrapper" class="dataTables_wrapper form-inline" role="grid">
		        				<button class="btn btn-success" type="button" data-toggle="modal" data-target="#addNewCoupons">新增优惠卷</button>
		        				<div class="span6">
		        					<h4>优惠卷列表:</h4>
		       		 			</div>
		       				</div>
		       				<!--表格开始  -->
			       			<table class="display table table-bordered table-striped dataTable table-hover" id="dynamic-table" aria-describedby="dynamic-table_info">
			        			<thead>
						        	<tr role="row">
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 80px;" aria-label="Rendering engine: activate to sort column ascending">优惠卷id</th>						        	
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 100px;" aria-label="Rendering engine: activate to sort column ascending">额度</th>						        							        		
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 80px;" aria-label="Rendering engine: activate to sort column ascending">满多少减</th>						        	
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 100px;" aria-label="Rendering engine: activate to sort column ascending">开始时间</th>	
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 80px;" aria-label="Rendering engine: activate to sort column ascending">失效时间</th>						        	
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 100px;" aria-label="Rendering engine: activate to sort column ascending">开始字段</th>							        								        	
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 100px;" aria-label="Rendering engine: activate to sort column ascending">失效字段</th>
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 100px;" aria-label="Rendering engine: activate to sort column ascending">
											<select id="forMeSelect" onchange="getAllCouponsByForMe()">
												<option value="3">优惠卷所属人群</option>
												<option value="0">普通顾客</option>
												<option value="1">经销商推荐顾客</option>										
											</select>
						        		</th>
						        		<th class="sorting" role="columnheader" tabindex="0" aria-controls="dynamic-table" rowspan="1" colspan="1" style="width: 100px;" aria-label="Rendering engine: activate to sort column ascending">编辑</th>
						        	</tr>
						        </thead>
							    <tbody role="alert" aria-live="polite" aria-relevant="all">
							    	<c:forEach var="coupon" items="${coupons}">
							        	<tr class="gradeA even" >
							           		<td class="">${coupon.couponsId}</td>			           				
								            <td class="">${coupon.knock}</td>											                    												            							            								            							          		           				
								            <td class="">${coupon.fullRedultion}</td>	
							           		<td class="">
							           		<fmt:formatDate value="${coupon.beginTime}" pattern="YYYY-MM-dd HH:mm:ss"/>
							           		</td>			           				
								            <td class="">
								            <fmt:formatDate value="${coupon.failureTime}" pattern="YYYY-MM-dd HH:mm:ss"/>
								            </td>										                       												            							            								            							         	           				
								            <td class="">${coupon.beginString}</td>			
								            <td class="">${coupon.overString}</td>		
								            <td class="">
								            	<c:if test="${coupon.forWho==0}">
								            		普通顾客
								            	</c:if>
								            	<c:if test="${coupon.forWho==1}">
								            		经销商推荐顾客
								            	</c:if>								            
								            </td>								            						            
								          	<td class="">
								          		<button class="btn btn-info" type="button" onclick="toUpdatedealer(${coupon.couponsId})" data-toggle="modal" data-target="#updateNewCoupons">修改</button>						      
								          	</td>						            
								        </tr>							    		
							    	</c:forEach>
							  	</tbody>
							</table>
							<!-- 表格结束 -->
							<!-- 分页开始 -->
						  	<div class="row-fluid">
							  	<div class="span6">
								  	<div class="dataTables_paginate paging_bootstrap pagination">
									  	<ul>									  		
								  			<c:choose>
									  			<c:when test="${page.currentPage==1}">
									  				<li class="prev">
									  					<a class="page-link">← 上一页</a>
									  				</li>
									  			</c:when>
									  			<c:otherwise>
									  				<li class="prev">
									  					<a href="../coupons/couponsSet.do?currentPage=${page.currentPage-1}" class="page-link">← 上一页</a>
									  				</li>
									  			</c:otherwise>	 							  			
								  			</c:choose>
						                  <c:forEach begin="1" end="${page.totalPage}" var="p">
						                    	<c:choose>
						                    		<c:when test="${page.currentPage==p}">
						                    			<c:if test="${p==1}">
						                    				<li  class="active page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p}" class="page-link">${p}</a></li> 
						                    				<c:if test="${page.totalPage>1}">
						                    					<li  class="page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p+1}">${p+1}</a></li>
						                    				</c:if>
						                    				<c:if test="${page.totalPage>2}">
						                    					<li  class="page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p+2}">${p+2}</a></li>
						                    				</c:if>
						                    				<c:if test="${page.totalPage>3}">
							                    				<li class="page-item"><a class="page-link" href="#">...</a></li>
							                    			</c:if>
						                    			</c:if>
						                    			<c:if test="${p>1}">                   			                   			
							                    			<c:if test="${p<page.totalPage}">
							                    				<c:if test="${p>2}">
							                    					<li class="page-item"><a class="page-link" href="#">...</a></li>
							                    				</c:if>
							                    				<li class="page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p-1}">${p-1}</a></li>
							                    				<li class="active page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p}" class="current_page">${p}</a></li>
							                    				<c:if test="${page.totalPage>2}">
							                    					<li class="page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p+1}">${p+1}</a></li>
							                    				</c:if>
							                    				<c:if test="${page.totalPage-p>1}">
							                    					<li class="page-item"><a class="page-link" href="#">...</a></li>
							                    				</c:if>
							                    			</c:if>
							                    			<c:if test="${p==page.totalPage}">
							                    				<c:if test="${p>3}">
							                    					<li class="page-item"><a class="page-link" href="#">...</a></li>
							                    				</c:if>
							                    				<c:if test="${p>2}">
							                    					<li class="page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p-2}">${p-2}</a></li>
							                    				</c:if>
							                    				<li class="page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p-1}">${p-1}</a></li>
							                    				<li class="active page-item"><a class="page-link" href="../coupons/couponsSet.do?currentPage=${p}" class="current_page">${p}</a></li>
							                    			</c:if>
						                    			</c:if>
						                    		</c:when>
						                    	</c:choose>
						                    </c:forEach>					

								  			<c:choose>
									  			<c:when test="${page.currentPage==page.totalPage}">
									  					<li class="pre"><a class="page-link">下一页 → </a></li>
									  			</c:when>
									  			<c:otherwise>
									  					<li class="pre"><a href="../coupons/couponsSet.do?currentPage=${page.currentPage+1}" class="page-link">← 下一页</a>
									  					</li>
									  			</c:otherwise>	 							  			
								  			</c:choose>
											<li class="page-item"> <a class="page-link">总共${page.totalPage}页</a></li>
									  	</ul>
								  	</div>
								</div>
							</div>
							<!-- 分页结束 -->
						</div>
					</div>
        		</section>
        	</div>
       </div>					
		<!-- 内容结束 -->
	</div>
</section>

      <!-- 新增优惠卷模态框 -->
		<div class="modal fade" id="addNewCoupons" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog">
		    <div class="modal-content" style="width: 841px;">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
		        <h4 class="modal-title" id="myModalLabel">新增优惠卷</h4>
		      </div>
		      <div class="modal-body">
		       <!--这是模态框内容  -->
		      	 <form action="" method="post" id="addNewCouponsFrom">
					<div class="form-group">
	                   <label class="col-md-2 col-sm-2 control-label">额度:</label>
	                   <div class="col-md-4">
	                       <input size="16" type="text" name="knock">
	                   </div>
	               </div><br>		       
				   <div class="form-group">
	                   <label class="col-md-2 col-sm-2 control-label">满多少减:</label>
	                   <div class="col-md-4">
	                       <input size="16" type="text" name="fullRedultion">
	                   </div>
	               </div><br>		       
					<div class="form-group">
	                   <label class="col-md-2 col-sm-2 control-label">生效时间:</label>
	                   <div class="col-md-4">
	                       <input size="16" type="text" value="2016-12-26 14:45:00" class="form_datetime form-control" name="beginTime">
	                   </div>
	               </div>	<br>	       
				   <div class="form-group">
	                   <label class="col-md-2 col-sm-2 control-label">失效时间:</label>
	                   <div class="col-md-4">
	                       <input size="16" type="text" value="2016-12-26 14:45:00" class="form_datetime form-control" name="failureTime">
	                   </div>
	               </div>	<br>
					<div class="form-group">
	                   <label class="col-md-2 col-sm-2 control-label">开始字段:</label>
	                   <div class="col-md-4">
	                       <input size="16" type="text" name="beginString">
	                   </div>
	               </div>	<br>		
	               <div class="form-group">
	                   <label class="col-md-2 col-sm-2 control-label">失效字段:</label>
	                   <div class="col-md-4">
	                       <input size="16" type="text" name="overString">
	                   </div>
	               </div><br>
				   <div class="form-group">
				    <label class="col-sm-2 control-label">优惠卷所属人群</label>
				  </div>	
				  <div id="activityStatus" style="position: relative; margin-left: 259px;">
					<div class="radio">
					  <label>
					    <input type="radio" name="forWho" id="openStatus" value="0">
					    	普通顾客
					  </label>
					</div>
					<div class="radio">
					  <label>	<!--  optionsRadios-->
					    <input type="radio" name="forWho" id="closeStatus" value="1" >
					    	经销商推荐顾客
					  </label>
					</div>				  
				  </div>				                 	       
		       	 </form>
		       <!-- 这是模态框内容结束 -->
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		        <button type="submit" class="btn btn-default" data-dismiss="modal" onclick="addNewCoupons()">保存</button>
		      </div>
		    </div>
		  </div>
		</div> 
       
		<!-- 模态框结束 -->
      <!-- 修改优惠卷模态框 -->
		<div class="modal fade" id="updateNewCoupons" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-dialog">
		    <div class="modal-content" style="width: 841px;">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
		        <h4 class="modal-title" id="myModalLabel">新增优惠卷</h4>
		      </div>
		      <div class="modal-body">
		       <!--这是模态框内容  -->
			       <form action="" method="post" id="updateCouponsFrom">
			       		<input type="hidden" name="couponsId">
						<div class="form-group">
		                   <label class="col-md-2 col-sm-2 control-label">额度:</label>
		                   <div class="col-md-4">
		                       <input size="16" type="text" name="knock">
		                   </div>
		               </div><br>		       
						<div class="form-group">
		                   <label class="col-md-2 col-sm-2 control-label">满多少减:</label>
		                   <div class="col-md-4">
		                       <input size="16" type="text" name="fullRedultion">
		                   </div>
		               </div><br>		       
						<div class="form-group">
		                   <label class="col-md-2 col-sm-2 control-label">生效时间:</label>
		                   <div class="col-md-4">
		                       <input size="16" type="text" value="" class="form_datetime form-control" name="beginTime">
		                   </div>
		               </div>	<br>	       
					   <div class="form-group">
		                   <label class="col-md-2 col-sm-2 control-label">失效时间:</label>
		                   <div class="col-md-4">
		                       <input size="16" type="text" value="" class="form_datetime form-control" name="failureTime">
		                   </div>
		               </div><br>
						<div class="form-group">
		                   <label class="col-md-2 col-sm-2 control-label">开始字段:</label>
		                   <div class="col-md-4">
		                       <input size="16" type="text" name="beginString">
		                   </div>
		               </div>	<br>		
		               <div class="form-group">
		                   <label class="col-md-2 col-sm-2 control-label">失效字段:</label>
		                   <div class="col-md-4">
		                       <input size="16" type="text" name="overString">
		                   </div>
		               </div><br>
					   <div class="form-group">
					    <label class="col-sm-2 control-label">优惠卷所属人群</label>
					  </div>	
					  <div id="activityStatus" style="position: relative; margin-left: 259px;">
						<div class="radio">
						  <label>
						    <input type="radio" name="forWho" id="openStatus2" value="0">
						    	普通顾客
						  </label>
						</div>
						<div class="radio">
						  <label>	<!--  optionsRadios-->
						    <input type="radio" name="forWho" id="closeStatus2" value="1" >
						    	经销商推荐顾客
						  </label>
						</div>				  
					  </div>				                 	       
			       </form>
		       <!-- 这是模态框内容结束 -->
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
		        <button type="submit" class="btn btn-default" data-dismiss="modal" onclick="updateCoupons()">保存</button>
		      </div>
		    </div>
		  </div>
		</div> 
       
		<!-- 模态框结束 -->		

</body>
<script type="text/javascript" src="../js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script src="../js/pickers-init.js"></script>
<script type="text/javascript">
	function getAllCouponsByForMe(){
		window.location.href="../coupons/couponsSet.do?currentPage=1&&forWho="+$('#forMeSelect').val();
	}



	//点击修改
	function toUpdatedealer(couponsId){
		$.post(
			"../coupons/getCouponsByCouponsId.do",
			{couponsId:couponsId},
			function(data){
				//把coupons赋值到弹出的页面
				$("#updateNewCoupons").find("input").each(function(i,inputLable){
						if($(inputLable).attr("name")=="couponsId"){
							$(inputLable).val(data.couponsId);
						}
						if($(inputLable).attr("name")=="knock"){
							$(inputLable).val(data.knock);
						}
						if($(inputLable).attr("name")=="fullRedultion"){
							$(inputLable).val(data.fullRedultion);
						}
						if($(inputLable).attr("name")=="beginTime"){
							$(inputLable).val(data.beginTime);
						}
						if($(inputLable).attr("name")=="failureTime"){
							$(inputLable).val(data.failureTime);
						}
						if($(inputLable).attr("name")=="beginString"){
							$(inputLable).val(data.beginString);
						}
						
						if($(inputLable).attr("name")=="overString"){
							$(inputLable).val(data.overString);
						}
				});
						if(data.forWho==0){
							$("#openStatus2").prop("checked",true);
						}else if(data.forWho==1){
							$("#closeStatus2").prop("checked",true);
						}			
						
			},
			"json"
		);
	}
	


	//这是增加新商品
	function addNewCoupons(){
		var tes=$("#addNewCouponsFrom").serialize();		
		$.post(
			"../coupons/addNewCoupons.do",
			$("#addNewCouponsFrom").serialize(),
			function(data){
				if(data==1){
					success("增加新优惠卷成功!");
					setTimeout(myfresh,2000);
				}
			},
			"json"
		);
	}
	//这是修改商品
	function updateCoupons(){
		$.post(
				"../coupons/updateCoupons.do",
				$("#updateCouponsFrom").serialize(),
				function(data){
					if(data==1){
						success("修改新优惠卷成功!");
						setTimeout(myfresh,2000);
					}
				},
				"json"
			);
	}
	//操作成功之后提示
	function success(text){
		  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
		  $("#menus").click();
	 
	}
	//操作失败之后提示

	function fail(text){
		  $("#alerts").html("<div  style='text-align: center; display:no;' class='alert alert-success alert-dismissable'><strong>"+text+"</strong></div>");
		  $("#menus").click();

	}
	function myfresh(){
		window.location.href=window.location.href;
	}
</script>
</html>
